﻿<nav class="navbar-default navbar-static-side" role="navigation">
    <div class="nav-close">
        <i class="fa fa-times-circle"></i>
    </div>
    <div class="sidebar-collapse">
        <ul class="nav" id="side-menu">
            <li class="nav-header">
                <div class="dropdown profile-element">
                   @* <span><img width="64" height="64" alt="image" class="img-circle" src="/UploadFiles/GetFile/d226ad89-f390-4e57-932d-a71ae6c402f5" /></span>*@
                    <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                        <span class="clear">
                            <span class="block m-t-xs"><strong class="font-bold">姓名：@*@(Gxu.Cisco.BLL.UserLogin.CurrUserData?.RealName ?? "未登录")*@</strong></span>
                            <span class="text-muted text-xs block">角色：@*@(Gxu.Cisco.BLL.UserLogin.CurrUserData?.AdminTypeName ?? "未登录")*@<b class="caret"></b></span>
                        </span>
                    </a>
                    <ul class="dropdown-menu animated fadeInRight m-t-xs">
                        <li>
                            <a class="J_menuItem" href="">修改头像</a>
                        </li>
                        <li>
                            <a class="J_menuItem" href="">个人资料</a>
                        </li>
                        <li>
                            <a class="J_menuItem" href="">联系我们</a>
                        </li>
                        <li>
                            <a class="J_menuItem" href="">信箱</a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="@Url.Action("Logout", "Account")">安全退出</a>
                        </li>
                    </ul>
                </div>
            </li>
            <li>
                    <a href="#">
                        <i class="fa fa-home"></i>
                        <span class="nav-label">主页</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li>
                            <a class="J_menuItem" href="index_v1.html" data-index="0">主页示例一</a>
                        </li>
                        <li>
                            <a class="J_menuItem" href="index_v2.html">主页示例二</a>
                        </li>
                        <li>
                            <a class="J_menuItem" href="index_v3.html">主页示例三</a>
                        </li>
                        <li>
                            <a class="J_menuItem" href="index_v4.html">主页示例四</a>
                        </li>
                    </ul>

                </li>
        </ul>
    </div>
</nav>
<script>
    var initMenu = function () {
        $.post("@Url.Action("GetMenu","Manager")", null, function (result) {
            if (!result || typeof result !== "object" || result.length<1) {
                return;
            }
            menuLoadData(result);
            //渲染菜单
            $("#side-menu").metisMenu();
            contabs();
        });

        $("#side-menu").metisMenu();
        contabs();
        function menuLoadData(treeObj) {
            for (var i = 0; i < treeObj.length; i++) {
                var item = treeObj[i];
                dsei(item);
                if (item.hasChildren) {
                    dsei2(item.ChildNodes);
                }
            }
        }
        //一级菜单
        function dsei(data) {
            var ulMenu = $('ul#side-menu');
            var url = data.url ? data.url : "#";
            var fallow = data.hasChildren ? '<span class="fa arrow"></span>' : '';
            var zsul = '<li id="' + data.id + '"><a href="' + url + '"><i class="fa fa-edit "></i> <span class="nav-label">' + fallow+ data.name + '</span></a></li>';
            ulMenu.append(zsul);
        }
        //下级菜单
        function dsei2(data) {
            if (data.length < 1) return;
            var $li = $("li#" + data[0].parentId);//父级li
            var ul = '<ul class="nav nav-second-level"></ul>';//添加子级容器
            $li.append(ul);
            var $ul = $li.find("ul");
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                var hasChildren = data.hasChildren;
                var url = item.url ? item.url : "#";
                var fallow = hasChildren ? '<span class="fa arrow"></span>' : '';
                var menuTab = hasChildren ? '><i class="fa fa-edit "></i':'class="J_menuItem"';
                var zsul = '<li id="' + item.id + '"><a href="' + url + '" ' + menuTab + '>' + fallow + item.name + '</a></li>';
                $ul.append(zsul);
                if (hasChildren) {
                    dsei2(item.ChildNodes);
                }
            }
        }
    }
</script>
